﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
using System.Text;

namespace WebOrder.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrderController : ControllerBase
    {

        private readonly IConfiguration configuration;

        public OrderController(IConfiguration configuration)
        {
            this.configuration = configuration;
        }

        public string GetOrderById(long id)
        {

            return id.ToString()+ "来自: " + configuration["urls"] + "的应答";
        }

        public bool SaveOrderById(long id)
        {
            string serverFile =  Directory.GetCurrentDirectory();
            using (FileStream m_FileStream = new FileStream(serverFile+@"/file.txt", FileMode.OpenOrCreate))
            {
                string str = "查看的是"+id.ToString()+"     路径："+ serverFile + "   时间:"+DateTime.Now.ToString();
                var b = Encoding.UTF8.GetBytes(str);
                m_FileStream.Write(b,0,b.Length);
                m_FileStream.Close();
            }
                
            

          

            return true;
        }
    }
}
